<template>
  <view class="wrap">
    <view class="hd">
      <view class="icon">
        <image src="../../static/time.png" class="img"></image>
      </view>
      <view class="font">待付款</view>
    </view>
    <view class="user">
      <view class="title">{{ detail.target_name }}</view>
      <view class="coin"><image src="../../static/currency.png" class="img"></image>{{ detail.coin }}投研币</view>
    </view>
    <view class="line">
      <uv-line color="#979797"></uv-line>
    </view>
    <view class="time">开始时间：{{ timeFormat(detail.start_time, 'yyyy-mm-dd hh:MM') }}</view>
    
    <view class="footer">
      <view class="desc">合计：<text class="red">{{ detail.coin }}</text> 投研币</view>
      <view class="last">当前账户余额{{ userInfo.coin }}投研币</view>
      <button class="btn" hover-class="none" v-if="detail.coin > userInfo.coin" @click="goMoneyUp">余额不足，去充值</button>
      <button class="btn" hover-class="none" v-else @click="goPay">去支付</button>
      <uv-safe-bottom></uv-safe-bottom>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { post } from '@/api';
import { useUser } from '@/store';
import { getUser } from '@/common';
import { deepClone, timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js';

let opt = '';
const userInfo = computed(() => {
  const store = useUser();
  return store.userInfo;
});
let detail = ref({});

onLoad((option) => {
  const value = uni.getStorageSync('investValue');
  if (value) {
    opt = deepClone(value);
    getData();
  }
})

function goPay(){
  post('api/survey/surveyEnroll', opt).then(res => {
    if(res.code == 1){
      getUser();
      uni.redirectTo({
        url: '/pages/success'
      });
    }
  })
}
function getData(){
  post('api/survey/getSurveyDetail', { survey_id: opt.survey_id }).then(res => {
    if(res.code == 1){
      const data = res.data;
      detail.value = data;
    }
  })
}
function goMoneyUp(){
  uni.navigateTo({
    url: '/pages/mine/money/topup',
  });
}
</script>

<style lang="scss" scoped>
  .footer{
    width: 100%;
    position: fixed;
    left: 0;
    bottom: 0;
    background-color: #fff;
    padding: 30rpx;
    .last{
      font-weight: 400;
      font-size: 24rpx;
      color: rgba(43, 43, 43, 0.46);
      text-align: center;
      padding-top: 17rpx;
      padding-bottom: 50rpx;
    }
    .desc{
      color: #2b2b2b;
      font-size: 28rpx;
      text-align: center;
      .red{
        color: #e43222;
        font-weight: 600;
      }
    }
    .btn{
      width: 432rpx;
      height: 72rpx;
      line-height: 72rpx;
      margin: 0 auto;
    }
  }
  .case{
    padding: 0 30rpx;
    padding-top: 26rpx;
    display: flex;
    align-items: center;
    .input{
      height: 72rpx;
      background: #FFFFFF;
      border: 1rpx solid #E8E8E8;
      border-radius: 4rpx;
      flex: 1;
    }
    .font{
      font-weight: 400;
      font-size: 26rpx;
      color: #797979;
      line-height: 60rpx;
    }
  }
  .integral{
    font-weight: 400;
    font-size: 22rpx;
    color: #E43222;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .disWord{
    font-weight: 400;
    font-size: 26rpx;
    color: #797979;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .time{
    font-weight: 400;
    font-size: 26rpx;
    color: #797979;
    padding-top: 30rpx;
    padding-left: 30rpx;
  }
  .line{
    padding: 0 30rpx;
    width: 100%;
  }
  .user{
    padding: 0 30rpx;
    padding-bottom: 50rpx;
    .coin{
      font-weight: 400;
      font-size: 26rpx;
      color: #E43222;
      padding-top: 28rpx;
      .img{
        width: 24rpx;
        height: 24rpx;
        margin-right: 10rpx;
      }
    }
    .title{
      height: 72rpx;
      line-height: 72rpx;
      padding: 0 45rpx;
      font-weight: 400;
      font-size: 26rpx;
      color: #C90000;
      background-color: rgba($color: #E43222, $alpha: .14);
      border-radius: 44rpx;
    }
  }
  .hd{
    padding: 0 30rpx;
    width: 100%;
    display: flex;
    align-items: center;
    padding-top: 45rpx;
    padding-bottom: 26rpx;
    .font{
      font-weight: 500;
      font-size: 30rpx;
      color: #000000;
      padding-left: 15rpx;
    }
    .icon{
      width: 30rpx;
      height: 30rpx;
      font-size: 0;
    }
  }
</style>